package com.simple.datax.flow.service.impl;
import java.util.Date;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.simple.datax.flow.dao.ibatis.TaskMessageDao;
import com.simple.datax.flow.dao.ibatis.model.FlowActivityInstance;
import com.simple.datax.flow.dao.ibatis.model.TaskDec;
import com.simple.datax.flow.dao.ibatis.model.TaskMessage;
import com.simple.datax.flow.message.EcFlowMessage;
import com.simple.datax.flow.service.TaskMessageManager;

/** 
 * @Title: TaskMessageManagerImpl.java 
 * @Package com.simple.datax.flow.service.impl 
 * @Description: TODO(任务处理类) 
 * @author tonney 
 * @date 2012-12-31 上午11:18:21 
 * @version V1.0 
 */
public class TaskMessageManagerImpl implements TaskMessageManager {
	public Logger log = LoggerFactory.getLogger(this.getClass());

	private TaskMessageDao taskMessageDao;
    
	@Override
	public void saveTaskMessage(FlowActivityInstance activityInstance,EcFlowMessage ecMessage) {
		try{
			TaskMessage taskMessage = new TaskMessage();
			taskMessage.setMessageId(ecMessage.getFlowMessageHead().getMessageId());
			taskMessage.setCorpTaskId(ecMessage.getFlowMessageBody().getCorpTaskId());
			taskMessage.setInputDbTime(new Date());
			taskMessage.setTaskActivityNo(activityInstance.getActivityNo());
			taskMessage.setTaskId(ecMessage.getFlowMessageBody().getTaskId());
			taskMessage.setRecevierId(activityInstance.getActorIdTo());
			taskMessage.setSenderId(activityInstance.getActorIdFrom());
			taskMessage.setTaskActivityName(activityInstance.getActivityName());
			taskMessage.setMessage(ecMessage.getOrgXmlCode().getBytes());
			taskMessage.setStatus(1);
			taskMessageDao.saveTaskMessage(taskMessage);
		}catch(Exception e){
			log.error("TaskMessageManagerImpl::saveTaskMessage error=>"+e.toString());
		}
	}

	@Override
	public void saveTaskDec(TaskDec taskDec) {
		taskMessageDao.saveTaskDec(taskDec);
	}

	@Override
	public TaskDec getTaskDecByTaskid(String taskId) {
		return taskMessageDao.getTaskDecByTaskid(taskId);
	}

	public void setTaskMessageDao(TaskMessageDao taskMessageDao) {
		this.taskMessageDao = taskMessageDao;
	}
}
